import 'package:flutter/material.dart';
import 'package:yinshui_caiying/model/user_real_data_reault.dart';
import 'package:get/get_rx/src/rx_types/rx_types.dart';
import 'package:yinshui_caiying/utils/colors.dart';

class WaterUserListResultModel {
  late int code;
  late String message;
  late Content content;

  WaterUserListResultModel(
      {required this.code, required this.message, required this.content});

  WaterUserListResultModel.fromJson(Map<String, dynamic> json) {
    code = json['code'];
    message = json['message'];
    content = (json['content'] != null
        ? new Content.fromJson(json['content'])
        : null)!;
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['code'] = this.code;
    data['message'] = this.message;
    if (this.content != null) {
      data['content'] = this.content.toJson();
    }
    return data;
  }
}

class Content {
  late int total;
  late int page;
  late int perPage;
  late List<WaterUserItemModel> data;

  Content(
      {required this.total,
      required this.page,
      required this.perPage,
      required this.data});

  Content.fromJson(Map<String, dynamic> json) {
    total = json['total'];
    page = json['page'];
    perPage = json['per_page'];
    if (json['data'] != null) {
      data = <WaterUserItemModel>[];
      json['data'].forEach((v) {
        data.add(new WaterUserItemModel.fromJson(v));
      });
    }
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['total'] = this.total;
    data['page'] = this.page;
    data['per_page'] = this.perPage;
    if (this.data != null) {
      data['data'] = this.data.map((v) => v.toJson()).toList();
    }
    return data;
  }
}

///用水户模型
class WaterUserItemModel {
  /// 用水户id
  late int id;

  /// 门户号
  late String doorNo;

  ///水表类型,1是一体式，2是分体式
  late String tableType;

  ///水表号
  late String tableNum;

  ///用水户姓名
  late String username;

  ///身份证号
  late String identityCard;

  ///家庭人数
  late int familySize;

  ///电话
  late String phone;

  ///采集终端号
  late String? baseNum;

  ///卡号
  late String? cardNo;

  ///水表底数
  late String initNum;

  ///备注
  late String? note;

  ///是否养殖户
  late String isBreeder;

  ///养殖说明
  late String? breedNote;

  ///地址
  late String address;

  ///欠费时间
  late String? arrearsTime;

  ///余额
  late double surplus;

  ///补偿水量
  late double offset;

  ///创建时间
  late String createDate;

  ///行政区划id
  late int adId;

  ///行政区划code
  late String adCode;

  ///水价名称
  late String priceName;

  ///水价ID
  late int priceId;

  ///工程id
  late int projectId;

  ///工程名称
  late String projectName;

  ///行政区划名称
  late String adName;

  ///通讯时间
  late String? deviceTime;

  ///在线与否、onLine在线 offLine离线
  late String? equipStatus;

  ///获取设备状态名称
  String getStatusName() {
    switch (this.equipStatus) {
      case 'onLine':
        return '在线';
      case 'offLine':
        return '离线';
      case 'sleep':
        return '休眠';
      default:
        return '-';
    }
  }

  ///获取设备状态颜色
  Color getStatusColor() {
    switch (this.equipStatus) {
      case 'onLine':
        return MyColors.main;
      case 'offLine':
        return Colors.red;
      case 'sleep':
        return Colors.orange;
      default:
        return Colors.red;
    }
  }

  ///电压
  late String? energy;

  ///累计流量
  late String? storeData;

  ///信号强度
  late String? signalStrength;

  ///水表阀门状态 1开，0关
  late String? isOpen;

  ///水表调试流程(默认是1)
  late int debugStep;

  ///水表通经
  late String meterDiameter;
  final realdata = UserRealDataModel(
          signal: '',
          status: '',
          switchStatus: '',
          totalFlow: '',
          voltage: '',
          time: '')
      .obs;

  WaterUserItemModel(
      {this.id = 0,
      this.doorNo = '',
      this.tableType = '',
      this.tableNum = '',
      this.initNum = '',
      this.username = '',
      this.identityCard = '',
      this.familySize = 1,
      this.phone = '',
      this.baseNum = '',
      this.cardNo = '',
      this.note = '',
      this.isBreeder = '0',
      this.breedNote = '',
      this.address = '',
      this.arrearsTime = '',
      this.surplus = 0,
      this.offset = 0,
      this.createDate = '',
      this.adId = 0,
      this.projectId = 0,
      this.priceName = '',
      this.priceId = 0,
      this.adName = '',
      this.projectName = '',
      this.deviceTime,
      this.equipStatus,
      this.energy,
      this.storeData,
      this.isOpen,
      this.signalStrength,
      this.adCode = '',
      this.meterDiameter = '',
      this.debugStep = 1});

  WaterUserItemModel.fromJson(Map<String, dynamic> json) {
    id = json['id'];
    doorNo = json['door_no'];
    tableType = json['table_type'];
    tableNum = json['table_num'];
    initNum = json['init_num'];
    username = json['username'];
    identityCard = json['identity_card'];
    familySize = json['family_size'];
    phone = json['phone'];
    baseNum = json['base_num'];
    cardNo = json['card_no'];
    note = json['note'];
    isBreeder = json['is_breeder'];
    breedNote = json['breed_note'];
    address = json['address'];
    arrearsTime = json['arrears_time'];
    surplus = json['surplus'];
    offset = json['offset'];
    createDate = json['create_date'];
    adId = json['ad_id'];
    projectId = json['project_id'];
    priceName = json['price_name'];
    priceId = json['price_id'];
    adName = json['ad_name'];
    projectName = json['project_name'];
    deviceTime = json['device_time'];
    equipStatus = json['equip_status'];
    signalStrength = json['signal_strength'];
    energy = json['energy'];
    storeData = json['store_data'];
    isOpen = json['is_open'];
    adCode = json['ad_code'];
    meterDiameter = json['meter_diameter'];
    debugStep = json['debug_step'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['id'] = this.id;
    data['door_no'] = this.doorNo;
    data['table_type'] = this.tableType;
    data['table_num'] = this.tableNum;
    data['init_num'] = this.initNum;
    data['username'] = this.username;
    data['identity_card'] = this.identityCard;
    data['family_size'] = this.familySize;
    data['phone'] = this.phone;
    data['base_num'] = this.baseNum;
    data['card_no'] = this.cardNo;
    data['note'] = this.note;
    data['is_breeder'] = this.isBreeder;
    data['breed_note'] = this.breedNote;
    data['address'] = this.address;
    data['arrears_time'] = this.arrearsTime;
    data['surplus'] = this.surplus;
    data['offset'] = this.offset;
    data['create_date'] = this.createDate;
    data['ad_id'] = this.adId;
    data['project_id'] = this.projectId;
    data['price_name'] = this.priceName;
    data['price_id'] = this.priceId;
    data['ad_name'] = this.adName;
    data['project_name'] = this.projectName;
    return data;
  }
}
